package com.example.juc.until;

import java.util.concurrent.FutureTask;

public class DeadLock {
    static  Object o1=new Object();
    static  Object o2=new Object();

    public static void main(String[] args) throws InterruptedException {

        new Thread(() ->{
            synchronized (o1) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("尝试获取o2");
                synchronized (o2){
                    System.out.println("获取o2");
                }
            }
        },"AA").start();

        new Thread(() -> {
            synchronized (o2) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("尝试获取o1");
                synchronized (o1){
                    System.out.println("获取o1");
                }
            }
        },"BB").start();


    }
}
